﻿using System;
using YArchitech.DataModel;

namespace YArchitech.Plumbing
{
	public class LayBasementSprinklerParameter
	{
		public LayBasementSprinklerParameter()
		{
			this.Elevation = 2.0;
			this.Radius = 0.0;
			this.LinkType = 1;
			this.Distance = 0.3;
			this.SelectType = 2;
			this.Init();
		}

		public double Elevation { get; set; }

		public double Radius { get; set; }

		public int LinkType { get; set; }

		public int PiptType { get; set; }

		public double Distance { get; set; }

		public int SelectType { get; set; }

		public string PiptTypeName { get; set; }

		public int nSign { get; set; }

		public void Init()
		{
			try
			{
				UserSetting userSetting = new UserSetting();
				string value = userSetting.GetValue("BasementSprinkler", "Elevation");
				if (!string.IsNullOrEmpty(value))
				{
					this.Elevation = Convert.ToDouble(value);
				}
				value = userSetting.GetValue("BasementSprinkler", "Radius");
				if (!string.IsNullOrEmpty(value))
				{
					this.Radius = Convert.ToDouble(value);
				}
				value = userSetting.GetValue("BasementSprinkler", "LinkType");
				if (!string.IsNullOrEmpty(value))
				{
					this.LinkType = Convert.ToInt32(value);
				}
				value = userSetting.GetValue("BasementSprinkler", "Distance");
				if (!string.IsNullOrEmpty(value))
				{
					this.Distance = Convert.ToDouble(value);
				}
				value = userSetting.GetValue("BasementSprinkler", "SelectType");
				if (!string.IsNullOrEmpty(value))
				{
					this.SelectType = Convert.ToInt32(value);
				}
				value = userSetting.GetValue("BasementSprinkler", "PiptTypeName");
				if (!string.IsNullOrEmpty(value))
				{
					this.PiptTypeName = value;
				}
				value = userSetting.GetValue("BasementSprinkler", "nSign");
				if (!string.IsNullOrEmpty(value))
				{
					this.nSign = int.Parse(value);
				}
				else
				{
					this.nSign = 1;
				}
			}
			catch
			{
			}
		}

		public void Save()
		{
			UserSetting userSetting = new UserSetting();
			userSetting.WriteValue("BasementSprinkler", "Elevation", this.Elevation.ToString());
			userSetting.WriteValue("BasementSprinkler", "Radius", this.Radius.ToString());
			userSetting.WriteValue("BasementSprinkler", "LinkType", this.LinkType.ToString());
			userSetting.WriteValue("BasementSprinkler", "Distance", this.Distance.ToString());
			userSetting.WriteValue("BasementSprinkler", "SelectType", this.SelectType.ToString());
			userSetting.WriteValue("BasementSprinkler", "PiptTypeName", this.PiptTypeName);
			userSetting.WriteValue("BasementSprinkler", "nSign", this.nSign.ToString());
		}
	}
}
